#include "StdAfx.h"
#include "VigenereAlpha.h"


VigenereAlpha::VigenereAlpha(const vector<int> & cle):Vigenere(cle)
{

}



char VigenereAlpha::Coder(char c, int rang){
	if (c >='A' && c<='Z')
		return 'A' + ((c-'A' + _cle[rang%_cle.size()]) % ('Z'-'A'+1));
	else if (c >='a' && c<='z')
		return 'a' + ((c-'a' + _cle[rang%_cle.size()]) % ('z'-'a'+1));
	else
		return c;
}
char VigenereAlpha::Decoder(char c, int rang){
	if (c >='A' && c<='Z')
		return 'A' + (c - 'A' - _cle[rang%_cle.size()] +('Z'-'A'+1)*(_cle[rang%_cle.size()]%('Z'-'A'+1)))%('Z'-'A'+1);
	else if (c >='a' && c<='z')
		return 'a' + (c - 'a' - _cle[rang%_cle.size()] +('z'-'a'+1)*(_cle[rang%_cle.size()]%('z'-'a'+1)))%('z'-'a'+1);
	else
		return c;
}